package com.practice.string;

import java.util.regex.Pattern;

public class RepeatedPattern {
	public boolean isRepeated(String word) {
		int N = word.length();
		boolean[] composite = new boolean[N+1];
		for (int i=2; i<=N; i++) {
			if (!composite[i]) {
				if (N%i == 0 &&
					Pattern.matches("^(" + word.substring(0, N/i) + ")*$", word)) return true;
				for (int j=i*2; j<=N; j+=i) composite[j] = true;
			}
		}
		return false;
	}
}
